<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<title>Zhangengru Navigation</title>
	</head>
	<style>
		/* 
		 *	Main-Yellow: #ffc301
		 *  Main-Black: #222222
		 */
		* {
			font-size: 14px;
			line-height: 20px;
			color: #ffc301;
			box-sizing: border-box;
			font-family: "microsoft yahei";
		}

		body {
			background-color: #ffc301;
			padding-top: 100px;
			width: 100%;
			height: 100%;
			min-width: 256px;
			overflow-x: hidden;
		}

		#main {
			width: 100%;
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;
		}

		.box {
			background-color: #222222;
			border-radius: 14px;
			margin: 14px;
			padding: 10px;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 250px;
			height: 410px;
		}

		.nodata {
			color: #444444;
			width: 100%;
			text-align: center;
			margin-top: 16px;
		}

		.item {
			width: 200px;
			height: 320px;
			overflow-y: auto;
			word-wrap: break-word;
			word-break: break-all;
		}

		.item::-webkit-scrollbar {
			width: 4px;
		}

		.item::-webkit-scrollbar-thumb {
			border-radius: 2px;
			box-shadow: none;
			background: #a88001;
		}

		.item::-webkit-scrollbar-track {
			box-shadow: none;
			border-radius: 2px;
			background: #444444;
		}

		.title {
			margin-bottom: 6px;
			margin-top: -6px;
			font-size: 20px;
			line-height: 34px;
			width: 100%;
			font-weight: 500;
			text-align: center;
		}

		.name {
			padding: 6px 4px;
			cursor: pointer;
			position: relative;
		}

		.name:hover {
			background-color: #FFC301;
			color: #222222;
			border-radius: 4px;
		}

		.search {
			position: fixed;
			top: 0px;
			left: 0px;
			width: 100%;
			height: 100px;
			background-color: rgba(255, 180, 0, 0.5);
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.search input {
			outline: none;
			border: none;
			background-color: #222222;
			height: 50px;
			padding: 15px;
			border-radius: 25px;
			width: 200px;
		}

		.btn {
			background-color: #222222;
			height: 50px;
			width: 50px;
			font-size: 25px;
			text-align: center;
			line-height: 50px;
			border-radius: 25px;
			cursor: pointer;
			margin: 0px 10px;
		}

		.btn:hover {
			background-color: #444444;
		}

		.search input:focus {
			border: none;
		}
	</style>
	<body>
		<div id="main"></div>
		<div class="search">
			<div class="btn" onclick="clearSearchRes()">✖</div>
			<input id="kw" onchange="inputChange()" />
			<div class="btn" onclick="confirmSearch()">✔</div>
		</div>
	</body>
	<script>
		const URL_DATA = [{
			title: "开发",
			urls: [{
				name: "Github代码托管",
				url: "https://github.com/"
			}, {
				name: "Leedcode刷算法",
				url: "https://leetcode-cn.com/"
			}, {
				name: "Go中文文档",
				url: "https://studygolang.com/pkgdoc"
			}, {
				name: "Android官方中文文档",
				url: "https://developer.android.google.cn/training/basics/firstapp/creating-project"
			}, {
				name: "Vue官方中文文档",
				url: "https://cn.vuejs.org/"
			}, {
				name: "ElementUI官方文档",
				url: "https://element.eleme.cn/2.13/#/zh-CN/component/installation"
			}, {
				name: "Java官方文档",
				url: "https://docs.oracle.com/javase/8/docs/api/"
			}, {
				name: "JavaScript官方文档",
				url: "https://developer.mozilla.org/zh-CN/docs/Web/JavaScript"
			}, {
				name: "Node.js官方文档",
				url: "https://nodejs.org/en/docs/"
			}, {
				name: "React官方中文文档",
				url: "https://react.docschina.org/"
			}, {
				name: "Webpack官网",
				url: "https://www.webpackjs.com/"
			}, {
				name: "Python文档",
				url: "https://docs.python.org/zh-cn/3/"
			}, {
				name: "Echart官网",
				url: "https://echarts.apache.org/zh/index.html"
			}, {
				name: "135编辑器",
				url: "https://www.135editor.com/"
			}]
		}, {
			title: "图形",
			urls: [{
                name:"uiGradients渐变色推荐搭配",
	            url:"https://uigradients.com/"
            },{
				name: "ColorHunt推荐颜色搭配",
				url: "https://colorhunt.co/",
			}, {
				name: "iconfont阿里图标库",
				url: "https://www.iconfont.cn/"
			}, {
				name: "wenhairu图片托管平台",
				url: "https://img.wenhairu.com/"
			}, {
				name: "觅元素",
				url: "http://www.51yuansu.com/"
			}, {
				name: "pexel高清免费图片素材",
				url: "https://www.pexels.com/zh-cn/"
			}, {
				name: "manyPixels等距插画素材",
				url: "https://www.manypixels.co/gallery/"
			}, {
				name: "simpleIcons知名企业LOGO图",
				url: "http://simpleicons.org/"
			}]
		}, {
			title: "影视",
			urls: [{
				name: "新GC网",
				url: "https://www.newcger.com/"
			}, {
				name: "爱给网",
				url: "http://www.aigei.com/"
			}]
		}, {
			title: "个人",
			urls: [{
				name: "个人博客园",
				url: "https://www.cnblogs.com/socaink/"
			}]
		}, ]
		const ITEM_TEMP =
			`<div class="box"><div><div class="title">{{title}}</div><div class="item">{{compileUrls}}</div></div></div>`
		const ITEM_URLS_TEMP = `<div class="name" onclick="openUrl('{{url}}')">{{name}}</div>`
		const NODATA_TEMP = `<div class='nodata'>暂无数据</div>`
		let Kw = ""

		function replaceTemp(str, data) {
			return str.replace(/\{\{(\w+)\}\}/g, function(match, key) {
				return data[key] === undefined ? "" : data[key]
			})
		}

		function isExistKw(source) {
			let s = JSON.parse(JSON.stringify(source.toLowerCase()))
			let t = JSON.parse(JSON.stringify(Kw.toLowerCase()))
			return s.indexOf(t) !== -1
		}

		function inputChange() {
			Kw = document.getElementById("kw").value
		}

		function confirmSearch() {
			let res = []
			for (let i = 0; i < URL_DATA.length; i++) {
				if (isExistKw(URL_DATA[i].title)) {
					res.push(URL_DATA[i])
					continue
				}
				for (let j = 0; j < URL_DATA[i].urls.length; j++) {
					if (isExistKw(URL_DATA[i].urls[j].name)) {
						if (res.length - 1 < i) {
							res.push({
								title: URL_DATA[i].title,
								urls: []
							})
						}
						res[i].urls.push(URL_DATA[i].urls[j])
					}
				}
			}
			renderMain(res)
		}

		function clearSearchRes() {
			renderMain(URL_DATA)
		}

		function openUrl(url) {
			window.open(url)
		}

		function renderMain(sourceData) {
			let data = JSON.parse(JSON.stringify(sourceData))
			if (data.length === 0) {
				document.getElementById("main").innerHTML = NODATA_TEMP
				return null
			}
			let mainHtml = ""
			for (let i = 0; i < data.length; i++) {
				let obj = data[i]
				obj.compileUrls = ""
				for (let j = 0; j < obj.urls.length; j++) {
					obj.urls[j].name = j + 1 + "." + obj.urls[j].name
					obj.compileUrls += replaceTemp(ITEM_URLS_TEMP, obj.urls[j])
				}
				mainHtml += replaceTemp(ITEM_TEMP, obj)
			}
			document.getElementById("main").innerHTML = mainHtml
		}

		renderMain(URL_DATA)
		document.onkeydown = function(event) {
			let e = event || window.event
			if (e && e.keyCode == 13) {
				confirmSearch()
			}
		}
	</script>
</html>
